﻿// CDeleDlg.cpp: 实现文件
//

#include "pch.h"
#include "SalaryManagement.h"
#include "CDeleDlg.h"
#include"InfoFile.h"


// CDeleDlg

IMPLEMENT_DYNCREATE(CDeleDlg, CFormView)

CDeleDlg::CDeleDlg()
	: CFormView(IDD_Dele)
	 //m_price(_T(""))
	, m_num(0)
	, m_price(0)
{

}

CDeleDlg::~CDeleDlg()
{
}

void CDeleDlg::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_COMBO1, m_combo);
	//DDX_Text(pDX, IDC_EDIT1, m_price);
	DDX_Text(pDX, IDC_EDIT2, m_num);
	DDX_Text(pDX, IDC_EDIT1, m_price);
}

BEGIN_MESSAGE_MAP(CDeleDlg, CFormView)
	ON_CBN_SELCHANGE(IDC_COMBO1, &CDeleDlg::OnCbnSelchangeCombo1)
	ON_BN_CLICKED(IDC_BUTTON1, &CDeleDlg::OnBnClickedButton1)
	ON_BN_CLICKED(IDC_BUTTON6, &CDeleDlg::OnBnClickedButton6)
END_MESSAGE_MAP()


// CDeleDlg 诊断

#ifdef _DEBUG
void CDeleDlg::AssertValid() const
{
	CFormView::AssertValid();
}

#ifndef _WIN32_WCE
void CDeleDlg::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif
#endif //_DEBUG


// CDeleDlg 消息处理程序


void CDeleDlg::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();

	// TODO: 在此添加专用代码和/或调用基类
	UpdateData(TRUE);
	CInfoFile file;
	file.ReadDocline();
	for (auto it : file.ls) {
		m_combo.AddString(CString(it.name.c_str()));
	}
	m_combo.SetCurSel(0);
	OnCbnSelchangeCombo1();

	UpdateData(FALSE);
}


void CDeleDlg::OnCbnSelchangeCombo1()
{
	// TODO: 在此添加控件通知处理程序代码
	int index = m_combo.GetCurSel();
	CString str;
	m_combo.GetLBText(index, str);
	CInfoFile file;
	file.ReadDocline();
	for (auto it : file.ls) {
		if (CString(it.name.c_str()) == str) {
			m_price = it.price;
			m_num = it.num;
			UpdateData(FALSE);
			break;
		}
	}
}


void CDeleDlg::OnBnClickedButton1()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	int index = m_combo.GetCurSel();
	CString str;
	m_combo.GetLBText(index, str);
	CInfoFile file;
	file.ReadDocline();
	for (list<msg>::iterator it = file.ls.begin(); it != file.ls.end();it++) {
		if (CString(it->name.c_str()) == str) {
			file.ls.erase(it);
			m_combo.SetCurSel(1);
			MessageBox(L"删除成功");
			break;
		}
	}
	file.WriteDocline();
}


void CDeleDlg::OnBnClickedButton6()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	m_num = 0;
	UpdateData(FALSE);
}
